package handlers

import (
	"go_async_task/utils/async_task"
)

type serviceStruct struct {
	Name string
}

func (s *serviceStruct) handleRecordsService() (map[string]interface{}, error) {
	ret := make(map[string]interface{})

	// 1、做自己的业务
	ret["data"] = map[string]interface{}{
		"result": "HelloWorld",
	}

	////2、请求 127.0.0.1:9000/index接口,跟主逻辑无关
	//errHandle := utils.HandleRequestIndex(s.Name)
	//if errHandle != nil {
	//	// 跟接口逻辑无关，出错不影响业务
	//	log.Println("errHandle: ", errHandle)
	//}

	// 3、异步请求
	//go func(name string) {
	//	_ = utils.HandleRequestIndex(name)
	//}(s.Name)

	// 4、将name构建好结构体放入channel
	currTask := async_task.TaskStruct{
		Name: s.Name,
	}
	async_task.ReportDataToTaskChannel(currTask)

	return ret, nil

}
